<template>
    <div class="app-container" style="padding:20px">
        <el-card>
            <FormTopBar title="招聘需求单" :flowInsId="form.flowInsId" :taskId="taskId" :businessId="form.id"
                        :billType="form.billType" @submitForm="submitForm"></FormTopBar>
        </el-card>

        <!--  -->
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="readonly">
            <el-card class="top15">
                <div slot="header" class="clearfix">
                    <span>基础信息</span>
                    <span style="float: right" v-if="form.id!=undefined">单据编号：{{form.billCode}}</span>
                </div>
                <el-form-item label="需求标题" prop="title">
                    <el-input v-model="form.title" placeholder="请输入需求标题"/>
                </el-form-item>
                <el-form-item label="责任人" prop="dutyUser">
                    <el-input v-model="form.dutyUser" placeholder="请输入责任人"/>
                </el-form-item>
                <el-form-item label="需求描述" prop="des">
                    <editor v-model="form.des" :min-height="300" :disabled="readonly"/>
                </el-form-item>
<!--                <el-form-item label="备注" prop="remark">-->
<!--                    <el-input v-model="form.remark" type="textarea" :rows="5" placeholder="请输入内容"/>-->
<!--                </el-form-item>-->
            </el-card>
        </el-form>
        <!--   岗位详情     -->
        <el-tabs type="border-card" class="top15 childList" v-if="form.id">
            <el-tab-pane>
                <span slot="label"><i class="el-icon-date"></i> 岗位详细信息</span>
                <RecruitDemandItem :demandId="form.id" :ifTab="true" :readonly="readonly"></RecruitDemandItem>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
import {addRecruitDemand, getRecruitDemand, updateRecruitDemand} from "@/api/hrm/recruitDemand";
import FlowInfo from "@/views/workflow/flow/flowInfo";
import FormTopBar from "@/views/workflow/common/formTopBar"
import RecruitDemandItem from "@/views/hrm/recruitDemandItem/index"

export default {
    name: "RecruitDemandForm",
    dicts: ['oa_flow_billstatus'],
    components:{FlowInfo,RecruitDemandItem,FormTopBar},
    data() {
        return {
            showFlowInfo:false,
            taskId:'',
            readonly:false,
            // 表单参数
            form: {
            },
            // 表单校验
            rules: {
                title: [
                    {required: true, message: "需求标题不能为空", trigger: "blur"}
                ]
            },
            showCommitDialog:false,
            commitType:"",
        };
    },
    provide(){
        return {
            addCcedList:this.addCcedList
        }
    },
    created() {
        //单据的id主键
        const formId = this.$route.params && this.$route.params.formId;
        //单据的类型
        const billType = this.$route.params && this.$route.params.billType;
        const taskId = this.$route.query && this.$route.query.taskId;
        const readonly = this.$route.query && this.$route.query.readonly;
        if(billType){
            this.form.billType = billType;
        }
        if(taskId){
            this.taskId = taskId;
        }
        if("1"==readonly){
            this.readonly = true;
        }
        if(formId){
            this.form.id = formId;
            this.getDetailData(formId);
        }
    },
    methods: {
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateRecruitDemand(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.closeThisPage();
                        });
                    } else {
                        addRecruitDemand(this.form).then(response => {
                            this.$modal.msgSuccess("保存成功，请继续填写招聘岗位信息");
                            this.$tab.closeOpenPage({ path: "/hrm/recruit/recruitDemand/form/"+response.data.id,query: {billType:this.form.billType}});
                        });
                    }
                }
            });
        },
        //  获取单据信息
        getDetailData(id) {
            getRecruitDemand(id).then(response => {
                this.form = response.data;
            });
        },
        closeThisPage(){
            this.$tab.closeOpenPage({ path: "/hrm/recruit/recruitDemand",query: {billType:this.form.billType}});
        },
        // 创建单据时候，选择了抄送人
        addCcedList(ccedList){
            this.form.ccedList = ccedList;
            console.log("回填抄送人")
            console.log(this.form)
        }
    }
};
</script>
<style scoped>
/deep/.childList .is-always-shadow{
    box-shadow: none !important;
}
</style>
